﻿<%--
 *  File:    VisitPlanSummary
 *  @Author: KentZhong 
 *  Date:    2009-10-9 10:02:44
 *
 *  Copyright (C) 2000 - 2009 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>
<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>


<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>


<%
String privilegeCode = "H0255,H0256";
  String strTableName = "v_visitplansummary";
  String strModuleName = "SFE";
	String contextPath = request.getContextPath();
%>
<%@ include file="/inc/Security.inc" %>
<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>
<html>
<head>
<title>FileRuleConfigSummary</title>

<PageFlow:CheckPageFlow pageName="p_visitplansummary"/>
<%@ include file="/inc/SumDiv.inc" %>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=contextPath%>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%=contextPath%>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/ScriptLib.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/SummaryDivision.js"></script>
<script language="JavaScript">
<%--  put your custom script here   --%>
function page_summary(actionvalue,orderbyname)
{
  var editform = summaryPrepare(cform,actionvalue,orderbyname);
  if(!editform) return;
  editform.action = "VisitPlanSummary.jsp?<%= OvalTools.randomURL() %>";
  editform.target = "_self";
  isRunning = true;
  editform.submit();
}

function page_radiotrue(obj,nyear,nmonth,nweek)
{
	
	radiotrue(obj);
	var cform = document.cform;
	 cform.year.value=nyear;
	 cform.monthofyear.value=nmonth;
	 
}	

function page_edit()
{
	var cform = document.cform;
	
	var year = cform.year.value;
	var monthofyear = cform.monthofyear.value;
	if(isEmpty(year) || year == -1 || isEmpty(monthofyear) || monthofyear == -1 ) return;
	
	self.location.href='VisitPlanEditFrm.jsp?year='+year+"&monthofyear="+monthofyear+"&contactid=<custom:write property="contactid"/>&orgid=<custom:write property="orgid"/>&ishistory=<custom:write property="ishistory"/>&flag=edit&<%= OvalTools.randomURL() %>";
	parent.downframesetid.cols="0,100%";
}
function page_new()
{
	<%
	Calendar nowCal = Calendar.getInstance();
	
	%>
	self.location.href="VisitPlanEditFrm.jsp?year=<%=nowCal.get(Calendar.YEAR)%>&monthofyear=<%=nowCal.get(Calendar.MONTH)+1%>&orgid=<custom:write property="orgid"/>&ishistory=N&contactid=<custom:write property="contactid"/>&flag=edit&<%= OvalTools.randomURL() %>";
	parent.downframesetid.cols="0,100%";
}

</script>
</head>

<body style="overflow: auto;">
<form name="cform" method="post" action="<%=contextPath%>/Dispatcher">
    <input type="hidden" name="pagename" value="p_visitplansummary">
    <input type="hidden" name="actionname">

<%--  page location   --%>
   

    <table width="100%" cellspacing="0" border="0" cellpadding="0">
      <tr>
<%--  search criteria  --%>
      </tr>
      <tr>
        <td>
          
          <table width="100%" border="0" cellspacing="0">
           
            <%@ include file="/inc/SummarySearch.inc" %>
            
            
          </table>
        </td>
      </tr>
      <tr>
        <td>
          <table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
             <tr class="deepblue-left"> 
          			<td class="title_center" width="22" >&nbsp;</td>
          			<td class="title_center" width="50"  ><%=label.getLabelName("L_Year")%></td>
          			<td class="title_center" width="50"  ><%=label.getLabelName("L_Month")%></td>
          			<td class="title_center" width="50" ><%=label.getLabelName("L_Week")%></td>
          			
          			<td class="title_center"  width="80" ><%=label.getLabelName("L_VisitPlanDate")%></td>
          		  <!--td class="title_center"  width="100" ><%=label.getLabelName("L_CustomerCode")%></td>
          		  <td class="title_center"   ><%=label.getLabelName("L_CustomerName")%></td>
          		  <td class="title_center"  width="120" ><%=label.getLabelName("L_OrgPCName")%></td-->
          		  <td class="title_center"   ><%=label.getLabelName("L_PlanActivityTypeInfo")%>
          		  
          		  <td class="title_center"  width="120" ><%=label.getLabelName("L_ProcessName")%></td>
          		  <td class="title_center"  width="80" ><%=label.getLabelName("L_VisitPlanStartTime")%></td>
          		  <td class="title_center"  width="80" ><%=label.getLabelName("L_VisitPlanEndTime")%></td>
          	</tr>			
            <%
              Integer nDefalultYear=null;
              Integer nDefalultMonthOfYear=null;
              String strClassType = ""; 
              String strIsChecked = "";  
              HashMap onePlanMap=null;
              Vector vPlans=(Vector)pageContext.getAttribute("visitplandetails");
              if(vPlans==null)
              	vPlans=new Vector();
              Iterator iter=vPlans.iterator();
              int j=0;
              int nMonthGroup=0;
              int nWeekGroup=0;
              int nMonthCount=0;
              int nWeekCount=0;
              Integer preYear=null;
              Integer preMonth=null;
              Integer preWeek=null;
              boolean yearGroup=false;
              boolean monthGroup=false;
              boolean weekGroup=false;
              int monthcolspan=1;
              int weekcolspan=1;
              StringBuffer sbfHtml=new StringBuffer();
              java.text.SimpleDateFormat timeFormatter = new java.text.SimpleDateFormat("HH:mm");  	
  						Date dStart=null;
  						Date dEnd=null;
              while(iter.hasNext())
              {	
              	onePlanMap=(HashMap)iter.next();
              	String strStartTime="";
              	String strEndTime="";
              	
              	dStart=(Date)onePlanMap.get("planstarttime");
              	dEnd=(Date)onePlanMap.get("planendtime");
              	if(dStart!=null)
              		strStartTime=timeFormatter.format(dStart);
              	if(dEnd!=null)
              		strEndTime=timeFormatter.format(dEnd);
              	
              	
              	pageContext.setAttribute("oneplandetail",onePlanMap);
              	if(preYear==null)
              	{
              		preYear=(Integer)onePlanMap.get("year");
              		preMonth=(Integer)onePlanMap.get("monthofyear");
              		preWeek=(Integer)onePlanMap.get("weekofmonth");
              		yearGroup=true;
              		monthGroup=true;
              		 weekGroup=true;
              		 nMonthCount=1;
              		 nWeekCount=1;
              		
              		 
              	}
              	else
              	{
              		 if(preYear.equals(onePlanMap.get("year")))
              		 		yearGroup=false;
              		 else
              		 {
              		 		preYear=(Integer)onePlanMap.get("year");
              		 		preMonth=(Integer)onePlanMap.get("monthofyear");
              		 		preWeek=(Integer)onePlanMap.get("weekofmonth");
              				yearGroup=true;
              				monthGroup=true;
              		 		weekGroup=true;
              		 		//nMonthCount=1;
              		 		//nWeekCount=1;
              		 }	 
              	}
              	if(!yearGroup)	
              	{
              		if(preMonth.equals(onePlanMap.get("monthofyear")))
              		{
              			monthGroup=false;
              			nMonthCount++;
              		}
              		else
              		{
              			  preMonth=(Integer)onePlanMap.get("monthofyear");
              		 		preWeek=(Integer)onePlanMap.get("weekofmonth");
              		 		monthGroup=true;
              		 		weekGroup=true;
              		 		//nWeekCount=1;
              		}	
              	}
              	if(!monthGroup)
              	{
              		if(preWeek.equals(onePlanMap.get("weekofmonth")))
              		{
              			weekGroup=false;
              			nWeekCount++;
              		}
              		else
              		{
              			 
              		 		preWeek=(Integer)onePlanMap.get("weekofmonth");
              		 		
              		 		weekGroup=true;
              		 		//nWeekCount=1;
              		}	
              	}
              	
	               strIsChecked = "";         
			           if ( j == 0 )
			           {
			               strIsChecked = "Checked";                       
			               nDefalultYear = preYear; 
			               nDefalultMonthOfYear= preMonth;         
			           } 

			           if ( j % 2 == 1 )  strClassType = "td-listrom";      
			           else  strClassType = "";
			           j++; 
            %>
          <%if(monthGroup){
          if(nMonthGroup>0){
          %>
          <script>
          	td__checkbox_<%=nMonthGroup-1%>.rowSpan=<%=nMonthCount%>;
          	td__year_<%=nMonthGroup-1%>.rowSpan=<%=nMonthCount%>;
          	td__month_<%=nMonthGroup-1%>.rowSpan=<%=nMonthCount%>;
          </script>	
          <%
          nMonthCount=1;
          }%>
          <tr onMouseOver="this.className='tr-over'" onMouseOut="this.className='<%=JspHelper.filterNull( strClassType )%>'" ); onClick="javascript:page_radiotrue('checkbox<%=JspHelper.filterNull(nMonthGroup  )%>','<%=preYear%>','<%=preMonth%>' , '<%=preWeek%>' )" class="<%=JspHelper.filterNull( strClassType )%>"> 
          
          <td rowspan="" id="td__checkbox_<%=nMonthGroup%>"><input type="radio" <%=strIsChecked%> id="checkbox<%=JspHelper.filterNull( nMonthGroup )%>" name="checkid"  class="checkbox" onClick="javascript:page_radiotrue('checkbox<%=JspHelper.filterNull( nMonthGroup )%>','<%=preYear%>','<%=preMonth%>' , '<%=preWeek%>')"></td>

          
          <td rowspan=""  id="td__year_<%=nMonthGroup%>">&nbsp;<%=preYear%></td>
					<td rowspan=""  id="td__month_<%=nMonthGroup%>">&nbsp;<%=preMonth%></td>
					<%
					nMonthGroup++;
					}
				else
				{
				%>
				<tr onMouseOver="this.className='tr-over'" onMouseOut="this.className='<%=JspHelper.filterNull( strClassType )%>'" ); onClick="javascript:page_radiotrue('checkbox<%=JspHelper.filterNull(nMonthGroup -1 )%>','<%=preYear%>','<%=preMonth%>' , '<%=preWeek%>' )" class="<%=JspHelper.filterNull( strClassType )%>"> 
          
				<%
					}
					if(weekGroup){
					if(nWeekGroup>0){
					%>
					<script>
						td__week_<%=nWeekGroup-1%>.rowSpan=<%=nWeekCount%>;
					</script>	
					<%
					nWeekCount=1;
					}%>
					<td rowspan=""  id="td__week_<%=nWeekGroup%>">&nbsp;<%=preWeek%></td>
					<%
					nWeekGroup++;
					}%>
					<td  class="td_right"> <custom:write name="oneplandetail" property="planvisitdate" dataType="date" dataFormatName="dateformat" nbsp="true"/></td>
					<!--td> <custom:write name="oneplandetail" property="customercode" nbsp="true"/></td>
					<td> <custom:write name="oneplandetail" property="customershortname" nbsp="true"/></td>
					<td> <custom:write name="oneplandetail" property="globalpcname" nbsp="true"/></td-->
					<td>
								<%pageContext.setAttribute("displayflag","view");%>
								<custom:selectdic name="oneplandetail" property="activitytype" dictType="PlanActivityType"  />
           		
							<%
							Integer activityType=(Integer)onePlanMap.get("activitytype");
							
							if(activityType.intValue()==1){
							%>
							
								(
								<a onclick=""><custom:write name="oneplandetail" property="customercode" nbsp="true"/></a>
									&nbsp;
								<custom:write name="oneplandetail" property="customershortname" nbsp="true" />
									&nbsp;
									<custom:selectdic name="oneplandetail" property="globalpccode" dictType="GlobalPCCode"  />
           		
								
									)
									
						
							<%}
							
							%>
								</td>
								<td><custom:select name="oneplandetail"  property="processid"  optionsName="allprocesses" optionValueKey="visitprocessid" optionInnerTextKey="processname"   defaultValue="---" defaultValueCost=" "/></td>
							<%pageContext.setAttribute("displayflag","");%>
					<!--td> <custom:write name="oneplandetail" property="processname" nbsp="true"/></td-->
					<td  class="td_right">&nbsp;<%=strStartTime%></td>
					<td  class="td_right">&nbsp;<%=strEndTime%></td>
        </tr>
            
            <%}
             if(nMonthGroup>0){
            %>
           
             <script>
          	td__checkbox_<%=nMonthGroup-1%>.rowSpan=<%=nMonthCount%>;
          	td__year_<%=nMonthGroup-1%>.rowSpan=<%=nMonthCount%>;
          	td__month_<%=nMonthGroup-1%>.rowSpan=<%=nMonthCount%>;
          </script>	
          <%
          nMonthCount=1;
          }
          if(nWeekGroup>0){%>
          <script>
						td__week_<%=nWeekGroup-1%>.rowSpan=<%=nWeekCount%>;
					</script>	
					<%
					nWeekCount=1;
					}%>
             <input type="hidden" name="year" value="<%=JspHelper.filterNull( nDefalultYear )%>">      
       			 <input type="hidden" name="monthofyear" value="<%=JspHelper.filterNull( nDefalultMonthOfYear )%>">      
       			 
            <%@ include file="/inc/SummaryAction.inc" %>
          </table>
          <%
          boolean isHistory="Y".equals(pageContext.getAttribute("ishistory"));
          if(!isHistory){
          %>
          <table width="100%" cellspacing="0" cellpadding="0">
            <tr><td class="summary_top"></td></tr>
            <tr>
              <td class="td_center">
             <a onclick="page_new();"><custom:button type="1" label="L_New" imgsrc="new.gif" border="0" style="width:60"/></a>
                
                <%
                  if(vPlans!=null && vPlans.size()>0){
              %>
              	<a onclick="page_edit();"><custom:button type="1" label="L_Edit" imgsrc="Modify.gif" border="0" style="width:60"/></a>
                
                <%}%>
              </td>
            </tr>
          </table>
          <%}%>
        </td>
      </tr>
    </table>
   
</form>
</body>
<script>
	parent.downframesetid.cols="250,72%";
</script>	
</html>